import {BrowserModule} from '@angular/platform-browser';
import {NgModule,CUSTOM_ELEMENTS_SCHEMA,NO_ERRORS_SCHEMA} from '@angular/core';
import {FormsModule} from '@angular/forms';

import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
// global layout
import {LayoutComponent} from './pages/global/layout/layout.component';
// common widget
import {AppHeaderComponent} from './widgets/header/header.component';
import {AppSidebarComponent} from './widgets/sidebar/sidebar.component';
import {AppFooterComponent} from './widgets/footer/footer.component';
import {AppBreadcrumbComponent} from './widgets/breadcrumb/breadcrumb.component';
import {AppPaginationComponent} from "./widgets/pagination/pagination.component";

// common service
import {AuthGuardService} from './services/auth-guard.service';
import {HttpClientService} from './services/http-client.service';


import {HttpModule, Http, RequestOptions} from '@angular/http';
import {AuthHttp, AuthConfig} from 'angular2-jwt';
import {AppPaginationModule} from "./widgets/pagination/pagination.module";
import {RX_ACTION_REDUCERS} from "./actionReducer/reducers.entry";
import {StoreModule} from "@ngrx/store";
import {AppWidgetsModule} from "./widgets/index";
/**
 * [authHttpServiceFactory 定义存储token的位置和名称]
 * @param {Http}           http    [description]
 * @param {RequestOptions} options [description]
 */
export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig({
    tokenName: 'token',
    tokenGetter: (() => sessionStorage.getItem('token')),
    globalHeaders: [{'Content-Type': 'application/json'}],
  }), http, options);
}

@NgModule({
  declarations: [
    AppComponent,
    LayoutComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    AppRoutingModule,
    AppWidgetsModule.forRoot(),
    StoreModule.provideStore(RX_ACTION_REDUCERS)
  ],
  providers: [{
    provide: AuthHttp,
    useFactory: authHttpServiceFactory,
    deps: [Http, RequestOptions]
  }, AuthGuardService, HttpClientService],
  bootstrap: [AppComponent]
})
export class AppModule {
}
